﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class BM_GoPay : System.Web.UI.Page
{
    HuatICBCPayService.ICBCService payService = new HuatICBCPayService.ICBCService();
    HuatICBCPayService.ICBC payICBCModel = new HuatICBCPayService.ICBC();

    protected void Page_Load(object sender, EventArgs e)
    {
        payService.CookieContainer = new System.Net.CookieContainer();
        
        if (payService.Verify("cet.huat.edu.cn", "8260147"))
        {
            string sOrderId = Request.QueryString[0].ToString();
            Security security = new Security();
            string orderId = security.DecryptQueryString(sOrderId);
            Exam.Update_OrderState(orderId, "5");
            DataTable dt = Exam.getOrderInfoByOrderID(orderId);
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                DataTable dtApply = Exam.ApplyInfo_GetInfoByOrder(orderId);
                if (dtApply.Rows.Count == 1)
                {
                    string payOrderId = "CET" + dtApply.Rows[0]["EmYear"].ToString() + dtApply.Rows[0]["EmNum"].ToString() + "-" + dr["OrderID"].ToString();
                    DataTable dtPayOrder = payService.GetOrderInfo(orderId);
                    if (dtPayOrder.Rows.Count > 0)
                    {
                        if (dtPayOrder.Rows[0]["transtat"].ToString() == "1")
                        {
                            Response.Redirect(BSUtility.mainUrl + "PayReturn.aspx?OrderID=" + payOrderId);
                        }
                    }

                    payICBCModel = payService.signData(payOrderId, dr["StudIdcard"].ToString(), "BMJF", dr["EmAllName"].ToString() + Session["userName"].ToString(), dr["EMCost"].ToString());
                    this.Controls.Add(new LiteralControl(payService.PostOrderForm(payICBCModel)));
                }
            }
            else
            {
                //BSUtility.WindowAlert(Page, "订单信息读取失败，请重新点击支付");
            }
        }
    }
}